package com.itheima.myreflect03;

import java.lang.reflect.Field;

public class Reflect01 {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchFieldException {
        //赋值
        //获取
        //method01();



        //创建一个class对象
        Class clazz = Class.forName("com.itheima.myreflect03.Student");


        //创建一个File对象
        Field money = clazz.getDeclaredField("money");
        money.setAccessible(true);


        //得到数据
        //创建一个对象
        Student stu1 = (Student) clazz.newInstance();
        Object o = money.get(stu1);
        System.out.println(o);


    }

    private static void method01() throws ClassNotFoundException, NoSuchFieldException, InstantiationException, IllegalAccessException {
        //创建一个class对象
        Class student = Class.forName("com.itheima.myreflect03.Student");

        //创建file对象
        Field name = student.getField("name");

        //创建对象
        Student stu = (Student) student.newInstance();
        name.set(stu,"张三");

        System.out.println(stu);
    }
}
